package basic.study.wantOffer.chapter6;

/**
 * @ClassName Problem64
 * @Description 求1+2+…+n
 * @Company inspur
 * @Author Kevin
 * @Date 2020/6/15 10:53
 * @Version 1.0
 */
public class Problem64 {
    /**
     * 用递归代替循环，用 && 代替if
     * @param n
     * @return
     */
    public int getSum(int n) {
        int sum = n;
        boolean flag = (n >1) && ((sum += getSum(n-1)) > 0);
        //boolean flag = (n > 1) || ((sum += getSum(n-1)) > 0)
        return sum;
    }
}
